package com.xiaoli.mss.util;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * Created by chenye on 2018/3/4.
 */
public class CryptographyUtil {
    public static String encBase64(String str) {
        return Base64.encodeToString(str.getBytes());
    }
    public static String decBase64(String str){
        return Base64.decodeToString(str);
    }
    public static String md5(String str,String salt){
        return new Md5Hash(str,salt).toString();
    }

    /**
     * shiro md5
     * @param target md5对象
     * @param salt 盐值
     * @param num hash次数
     * @return
     */
    public static String shiroMd5(String target,String salt,int num){
        Object obj = new SimpleHash("MD5", target, salt, num);
        return String.valueOf(obj);
    }
    public static void main(String[] args) {
        System.out.println(shiroMd5("root","root123",2));
        System.out.println(md5("root","chenye123"));
    }
}
